<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : Printorderhistory.xsl
    Created on : May 31, 2013, 1:12 AM
    Author     : annt60258
    Description:
        Purpose of transformation follows.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
 xmlns:ns='http://xml.netbeans.org/schema/orderuser_old'
exclude-result-prefixes="ns"
>
    <xsl:variable name="userID"/>
    <xsl:output method="html"/>
    <xsl:template name="formatdate">
        <xsl:param name="datestr" />
     <!-- input format mmddyyyy -->
     <!-- output format mm/dd/yyyy -->

        <xsl:variable name="mm">
            <xsl:value-of select="substring($datestr,6,2)" />
        </xsl:variable>

        <xsl:variable name="dd">
            <xsl:value-of select="substring($datestr,9,2)" />
        </xsl:variable>

        <xsl:variable name="yyyy">
            <xsl:value-of select="substring($datestr,1,4)" />
        </xsl:variable>

        <xsl:variable name="hh">
            <xsl:value-of select="substring($datestr,12,2)" />
        </xsl:variable>

        <xsl:variable name="mimi">
            <xsl:value-of select="substring($datestr,15,2)" />
        </xsl:variable>
        
        <xsl:variable name="ss">
            <xsl:value-of select="substring($datestr,18,2)" />
        </xsl:variable>

        <xsl:value-of select="$yyyy" />
        <xsl:value-of select="'-'" />
        <xsl:value-of select="$mm" />
        <xsl:value-of select="'-'" />
        <xsl:value-of select="$dd" />
        <xsl:value-of select="' '" />
        <xsl:value-of select="$hh" />
        <xsl:value-of select="':'" />
        <xsl:value-of select="$mimi" />
        <xsl:value-of select="':'" />
        <xsl:value-of select="$ss" />

        
    </xsl:template>


    <xsl:template match="/">
        <html>
            <body>
                <table style="width:500px" border="1">
                    <thead style="color:white" bgcolor="#1B9BE0">
                        <th>No.</th>
                        <th>Date buy</th>
                        <th>Receive</th>
                        <th>PrintPDF</th>
                    </thead>
                    <xsl:for-each select="//ns:Orderuser">
                        <tr style="color:black">
                            <td>
                                <xsl:value-of select="position()" />
                            </td>
                            <td>
                                <xsl:call-template name="formatdate">
                                    <xsl:with-param name="datestr" select="ns:OrderDate"/>
                                </xsl:call-template>
                            </td>
                            <xsl:variable name="recieve" select="ns:OrderStatus"/>
                            <td>
                                <xsl:choose>
                                    <xsl:when test="$recieve=1" >
                                        Yes
                                    </xsl:when>
                                   
                                    <xsl:otherwise>
                                        No
                                    </xsl:otherwise>
                                </xsl:choose>
                            </td>
                            <td>
                                <a target="_blank">
                                    <xsl:attribute name="href">PrintOrderHistory?idorder=<xsl:value-of select="ns:OrderID" /></xsl:attribute>PrintPDF
                                </a>
                            </td>
                        </tr>
                    </xsl:for-each>
                </table>
            </body>
        </html>
    </xsl:template>

</xsl:stylesheet>
